import {
  IResult,
  IDashboardSort,
  DashboardType,
  IDashboardConfig,
} from "../interfaces";
import { instance } from "../utils";

/** dashboard sort */
export const fetchDashboardSort = (
  spaceId: string,
  channelId: string
): Promise<IResult<IDashboardSort[]>> => {
  return instance
    .get(`/space/${spaceId}/channel/${channelId}/dashboard/sort`)
    .then(({ data }) => data);
};

/** dashboard data */
export const fetchDashboardData = (
  spaceId: string,
  channelId: string,
  dashboardId: string,
  body
): Promise<IResult<DashboardType>> => {
  return instance
    .post(
      `/space/${spaceId}/channel/${channelId}/dashboard/${dashboardId}`,
      body
    )
    .then(({ data }) => data);
};

/** dashboard config */
export const fetchDashboardConfig = (
  spaceId: string,
  channelId: string
): Promise<IResult<IDashboardConfig[]>> => {
  return instance
    .get(`/space/${spaceId}/channel/${channelId}/dashboardConfig`)
    .then(({ data }) => data);
};
